package core

import "fmt"

type ServerWebExchange interface {

	/**
	 * Return the current HTTP request.
	 */
	GetRequest() ServerHttpRequest

	/**
	 * Return the current HTTP response.
	 */
	GetResponse() ServerHttpResponse

	/**
	 * Return a mutable map of request attributes for the current exchange.
	 */
	GetAttributes() map[string]interface{}

	/**
	 * Return the request attribute value if present.
	 * @param name the attribute name
	 * @param <T> the attribute type
	 * @return the attribute value
	 */
	GetAttribute(name string) interface{}

	/**
	 * Return the request attribute value, or a default, fallback value.
	 * @param name the attribute name
	 * @param defaultValue a default value to return instead
	 * @param <T> the attribute type
	 * @return the attribute value
	 */
	GetAttributeOrDefault(name string, value interface{}) interface{}
}

type DefaultServerWebExchange struct {
	request    ServerHttpRequest
	response   ServerHttpResponse
	attributes map[string]interface{}
}

func (exchange *DefaultServerWebExchange) GetRequest() ServerHttpRequest {
	return exchange.request
}

func (exchange *DefaultServerWebExchange) GetResponse() ServerHttpResponse {
	return exchange.response
}

func (exchange *DefaultServerWebExchange) GetAttributes() map[string]interface{} {
	return exchange.attributes
}

func (exchange *DefaultServerWebExchange) GetAttribute(name string) interface{} {
	if exchange.attributes != nil {
		return exchange.attributes[name]
	}
	return nil
}

func (exchange *DefaultServerWebExchange) GetAttributeOrDefault(name string, value interface{}) interface{} {
	a := exchange.GetAttribute(name)
	if a != nil {
		return a
	}
	return value
}

func (exchange *DefaultServerWebExchange) initFormData(request ServerHttpRequest) {
	contentType := request.GetHeaders().GetContentType()
	fmt.Print(contentType)
}
